package com.snake.springboot.custom.controller.base;

import com.snake.springboot.custom.api.model.base.CustPointsFlowModel;
import com.snake.springboot.custom.api.model.common.KeyVal;
import com.snake.springboot.custom.api.model.points.PointsChangeType;
import com.snake.springboot.custom.api.request.base.CustPointsFlowQuery;
import com.snake.springboot.custom.api.request.page.PageQuery;
import com.snake.springboot.custom.api.service.base.CustPointsFlowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.snake.common.result.ResponseResult;
import org.snake.common.result.ResponseResultFactory;
import org.snake.common.result.ReturnList;
import org.snake.common.validate.Create;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>商户算力-算力流水
 * 类{@code CustPointsFlow} </br>
 * 创建时间2025/2/20 17:50
 * @author yangxt
 * @see
 */
@Api(tags = "商户算力-算力流水")
@RestController
@RequestMapping("/cust/points-flow")
public class CustPointsFlowController {
    @Autowired
    private CustPointsFlowService flowService;

    @ApiOperation("新增")
    @PostMapping("/add")
    public ResponseResult<CustPointsFlowModel> addCustPointsFlow(
            @ApiParam(name = "接口入参", value = "传入json格式", required = true)
            @RequestBody @Validated({Create.class}) CustPointsFlowModel model) {
        CustPointsFlowModel result = flowService.addCustPointsFlow(model);
        return ResponseResultFactory.ucc("添加成功！", result);
    }

    @ApiOperation("修改")
    @PostMapping("/modify")
    public ResponseResult<CustPointsFlowModel> modifyCustPointsFlow(
            @ApiParam(name = "接口模型入参", value = "传入json格式", required = true)
            @RequestBody CustPointsFlowModel model) {
        flowService.modifyCustPointsFlow(model);
        return ResponseResultFactory.ucc("修改成功！");
    }

    @ApiOperation("删除")
    @GetMapping("/remove/{id}")
    public ResponseResult<Object> remove(
            @ApiParam(name = "记录ID", value = "传入String类型", required = true)
            @PathVariable("id") String id) {
        flowService.removeCustPointsFlow(id);
        return ResponseResultFactory.ucc("移除成功！");
    }

    @ApiOperation("查询列表")
    @PostMapping("/list")
    public ResponseResult<ReturnList<CustPointsFlowModel>> queryCustPointsFlowList(
            @ApiParam(name = "查询条件", value = "传入json类型", required = true)
            @RequestBody PageQuery<CustPointsFlowQuery> params) {
        CustPointsFlowQuery params1 = params.getParams();
        if(!StringUtils.isEmpty(params.getCustomId())){
           params1.setCustomId(params.getCustomId());
        }
        ReturnList<CustPointsFlowModel> result = flowService.queryCustPointsFlowList(params);
        return ResponseResultFactory.ucc("查询成功！", result);
    }

    @ApiOperation("获取算力变动类型")
    @PostMapping("/change-type")
    public ResponseResult<List<KeyVal<Integer,String>>> changeType() {
        return ResponseResultFactory.ucc("查询成功！", PointsChangeType.getEnumList());
    }
}
